import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { dateTransformer } from '../../../../common/utils';

@Entity('order', {
  comment: '订单表',
})
export class OrderEntity {
  @PrimaryGeneratedColumn({ type: 'bigint', name: 'id', comment: '订单ID' })
  public id: number;

  @Column({ type: 'varchar', name: 'order_no', default: '', comment: '订单编号' })
  public orderNo: string;

  @Column({ type: 'varchar', name: 'transaction_id', default: '', comment: '微信支付订单号' })
  public transactionId: string;

  @Column({ type: 'bigint', name: 'user_id', default: null, comment: '用户ID' })
  public userId: number;

  @Column({ type: 'int', name: 'total_amount', default: null, comment: '订单总金额(分)' })
  public totalAmount: number;

  @Column({ type: 'int', name: 'pay_amount', default: null, comment: '实付金额(分)' })
  public payAmount: number;

  @Column({ type: 'int', name: 'discount_amount', default: 0, comment: '折扣金额(分)' })
  public discountAmount: number;

  @Column({ type: 'tinyint', name: 'order_status', default: 0, comment: '订单状态：0-待支付，1-已支付，2-已取消，3-已关闭，4-已退款' })
  public orderStatus: number;

  @Column({ type: 'tinyint', name: 'pay_type', default: null, comment: '支付方式：1-微信支付' })
  public payType: number;

  @Column({ type: 'varchar', name: 'product_name', default: '', comment: '商品名称' })
  public productName: string;

  @Column({ type: 'text', name: 'product_desc', default: null, comment: '商品描述' })
  public productDesc: string;

  @Column({ type: 'datetime', name: 'pay_time', default: null, comment: '支付时间' })
  public payTime: Date;

  @Column({ type: 'datetime', name: 'cancel_time', default: null, comment: '取消时间' })
  public cancelTime: Date;

  @Column({ type: 'datetime', name: 'close_time', default: null, comment: '关闭时间' })
  public closeTime: Date;

  @Column({ type: 'varchar', name: 'remark', default: '', comment: '备注' })
  public remark: string;

  @CreateDateColumn({ type: 'datetime', name: 'create_time', default: null, transformer: dateTransformer, comment: '创建时间' })
  public createTime: Date;

  @UpdateDateColumn({ type: 'datetime', name: 'update_time', default: null, transformer: dateTransformer, comment: '更新时间' })
  public updateTime: Date;
}
